/*
Copyright 2019 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

@import '../commons/index.css';

:root {
  --spectrum-menu-margin-x: var(--spectrum-global-dimension-size-40);
  --spectrum-selectlist-heading-text-size: var(--spectrum-global-dimension-font-size-100);
  --spectrum-selectlist-heading-text-font-weight: var(--spectrum-global-font-weight-bold);
  --spectrum-selectlist-heading-margin: var(--spectrum-global-dimension-size-75) 0 0 0;
  --spectrum-selectlist-heading-padding-left: var(--spectrum-global-dimension-size-150);
  --spectrum-selectlist-heading-padding-right: var(--spectrum-global-dimension-size-450);

  /* OVERRIDE: DNA uses a static size which doesn't properly adjust on large scale */
  /* Remove once https://git.corp.adobe.com/Spectrum/spectrum-dna/pull/409 is released. */
  --spectrum-selectlist-option-padding: var(--spectrum-global-dimension-size-150);

  --spectrum-selectlist-option-selectable-padding-right: calc(var(--spectrum-global-dimension-size-100) + var(--spectrum-icon-checkmark-medium-width) + var(--spectrum-selectlist-option-icon-padding-x));

  --spectrum-selectlist-option-icon-margin-top: var(--spectrum-global-dimension-size-50);

  /* Hardcoded for wrapping study */
  --spectrum-selectlist-option-label-line-height: 1.3;

  /* From spectrum: this value should be the same for both medium and large scale. */
  --spectrum-menu-max-width: 320px;
}

.spectrum-Menu-wrapper,
.spectrum-Menu-subdialog {
  overflow: hidden;
  max-height: 100%;
  display: inline-flex;
  flex-direction: column;
  border-radius: var(--spectrum-alias-border-radius-regular);
  border-style: solid;
  border-width: var(--spectrum-popover-border-size);
}

.spectrum-Menu-popover {
  max-width: var(--spectrum-menu-max-width);
}

.spectrum-Submenu-popover {
  margin: calc(var(--spectrum-global-dimension-size-65) * -1);
}

.spectrum-Menu {
  /*
    Menu border radius + 1 to match XD designs for submenu offset. No calc use so
    getComputedStyle + getPropertyValue actually returns a pixel value rather than the calc string.
  */
  --spectrum-submenu-offset-distance: var(--spectrum-global-dimension-size-65);
  text-align: start;
  display: block;

  box-sizing: border-box;

  padding: var(--spectrum-popover-padding-y) 0;
  margin: 0;

  list-style-type: none;

  overflow-y: auto;
  user-select: none;

  & .spectrum-Menu-sectionHeading {
    /* Support headings as LI */
    margin-block-start: var(--spectrum-global-dimension-size-75);
    margin-block-end: var(--spectrum-global-dimension-size-40);
  }

  &:focus {
    outline: none;
  }
}

.spectrum-Menu-checkmark {
  transform: scale(1);
  opacity: 1;
  box-sizing: content-box;
  /*
    Renamed from padding-y to padding-height to fix docs issue where fallback var replaced this value
    (due to old spectrum-css postcss-custom-properties-custom-mapping plugin).
  */
  padding-block-start: calc(var(--spectrum-selectlist-option-icon-padding-y) - var(--spectrum-selectlist-option-padding-height));
}

.spectrum-Menu-item {
  cursor: default;
  position: relative;
  display: block;

  box-sizing: border-box;

  margin: 0;

  border-inline-start: var(--spectrum-selectlist-border-size-key-focus) solid transparent;

  font-size: var(--spectrum-selectlist-option-text-size);
  font-weight: var(--spectrum-selectlist-option-text-font-weight);
  font-style: normal;
  text-decoration: none;

  &[href] {
    cursor: pointer;
  }

  &:focus {
    outline: none;
  }

  &.is-disabled {
    cursor: default;
  }

  &.is-selected {
    .spectrum-Menu-checkmark {
      display: block;
    }
  }

  .spectrum-Icon + .spectrum-Menu-itemLabel,
  .spectrum-Menu-itemIcon  + .spectrum-Menu-itemLabel {
    margin-inline-start: var(--spectrum-selectlist-thumbnail-image-padding-x);
  }
}

.spectrum-Menu-itemLabel {
  grid-area: text;
  line-height: var(--spectrum-global-font-line-height-small);
  word-break: break-word;
}

.spectrum-Menu-itemLabel--wrapping {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.spectrum-Menu-checkmark {
  display: none;
  align-self: flex-start;
  justify-self: end;
  grid-area: checkmark;
}

.spectrum-Menu-divider {
  /* Add the correct box sizing for hr in Firefox. */
  box-sizing: content-box;

  /* Show the overflow for hr in Edge and IE. */
  overflow: visible;

  block-size: var(--spectrum-selectlist-divider-size);
  margin: calc(var(--spectrum-selectlist-divider-padding) / 2) var(--spectrum-selectlist-option-padding);
  padding: 0 0;
  border: none;
}

.spectrum-Menu-sectionHeading {
  display: block;
  margin: var(--spectrum-selectlist-heading-margin);
  padding-top: 0;
  padding-bottom: 0;
  padding-inline-start: var(--spectrum-selectlist-heading-padding-left);
  padding-inline-end: var(--spectrum-selectlist-heading-padding-right);

  font-size: var(--spectrum-selectlist-heading-text-size);
  font-weight: var(--spectrum-selectlist-heading-text-font-weight);
  line-height: var(--spectrum-text-body-line-height);
}

.spectrum-Menu-section--noHeading {
  &.spectrum-Menu-section--isFirst {
    padding-top: 0;
  }
  &.spectrum-Menu-section--isLast {
    padding-bottom: 0;
  }
}

.spectrum-Menu .spectrum-Menu {
  /* Fill parent menu when nested */
  display: block;
  margin: 0;
}

.spectrum-Menu-itemGrid {
  display: grid;
  grid-template-columns: calc(var(--spectrum-selectlist-option-padding) - var(--spectrum-selectlist-border-size-key-focus)) auto 1fr auto auto auto auto var(--spectrum-selectlist-option-padding);
  /*
    Renamed from padding-y to padding-height to fix docs issue where fallback var replaced this value
    (due to old spectrum-css postcss-custom-properties-custom-mapping plugin).
  */
  grid-template-rows: var(--spectrum-selectlist-option-padding-height) 1fr auto var(--spectrum-selectlist-option-padding-height);
  grid-template-areas:
    ". .    .            .         .     .         .        ."
    ". icon text         checkmark end   keyboard  chevron  ."
    ". icon description  checkmark end   keyboard  chevron  ."
    ". .    .            .         .     .         .        .";
}

.spectrum-Menu-item.is-selectable {
  .spectrum-Menu-itemGrid {
    grid-template-columns: calc(var(--spectrum-selectlist-option-padding) - var(--spectrum-selectlist-border-size-key-focus)) auto 1fr calc(var(--spectrum-icon-checkmark-medium-width) + var(--spectrum-selectlist-option-icon-padding-x)) auto auto var(--spectrum-selectlist-option-padding);
  }
}

/* Added .spectrum-Menu so paddings from component styles are overridden */
.spectrum-Menu .spectrum-Menu-end {
  grid-area: end;
  justify-self: end;
  align-self: flex-start;
  padding-inline-start: var(--spectrum-global-dimension-size-250);
  box-sizing: content-box;
}
.spectrum-Menu-icon {
  grid-area: icon;
  /* Margin around the whole menu item is 6px. Icon should be 7px from the top according to XD. */
  padding-block-start: var(--spectrum-global-dimension-size-10);
  padding-inline-end: var(--spectrum-global-dimension-size-100);
}
.spectrum-Menu-avatar {
  /* Matches icon. */
  grid-area: icon;
  margin-inline-start: var(--spectrum-global-dimension-size-10);
  margin-inline-end: var(--spectrum-global-dimension-size-100);
}
.spectrum-Menu-description {
  grid-area: description;
  line-height: var(--spectrum-global-font-line-height-small);
  font-size: var(--spectrum-global-dimension-size-150);
}
.spectrum-Menu-keyboard {
  grid-area: keyboard;
  align-self: flex-start;
  padding-inline-start: var(--spectrum-global-dimension-size-125);
  /* override default browser styling. */
  /* keyboard shortcuts are always ASCII, so use base font */
  font-family: var(--spectrum-font-family-base);
  unicode-bidi: plaintext;
  text-align: end;
}

.spectrum-Menu-chevron {
  margin-inline-end: calc(var(--spectrum-global-dimension-size-50) * -1);
  grid-area: chevron;
  justify-self: end;
  align-self: flex-start;
  padding-inline-start: var(--spectrum-global-dimension-size-300);
  box-sizing: content-box;
}

.spectrum-Menu-wrapper {
  overflow: auto;

  .spectrum-Submenu-wrapper {
    display: flex;
    flex-direction: column;
    overflow: auto;

    &.spectrum-Submenu-wrapper--isMobile {
      overflow-x: hidden; /* Prevents scrollbar from appearing during submenu transition */
    }
  }

  &.spectrum-Menu-wrapper--isMobile {
    width: 100%;
    border: none;
    background-color: unset;
    opacity: 1;
    transition: opacity var(--spectrum-global-animation-duration-600) var(--spectrum-global-animation-ease-out);

    &.is-expanded {
      position: absolute;
      left: 100%;
      height: 0;
      border: 0;
      opacity: 0;
    }

    .spectrum-Submenu-headingWrapper {
      display: flex;
      margin: 4px 4px 0px 4px;

      .spectrum-Submenu-heading {
        display: flex;
        margin-top: 7px;
        margin-bottom: 0px;
        margin-inline-start: 4px;
        font-weight: var(--spectrum-selectlist-heading-text-font-weight);
        font-size: var(--spectrum-dialog-title-text-size);
        line-height: var(--spectrum-dialog-title-text-line-height);
      }
    }
  }
}
